zz_

isPrime.test.js

thoward37@gmail.com/shirt[create-new-file-named-isprime-js] / isPrime.test.js @ 9444005f Download
Ladder Summary

changed.

+import { describe, test } from "node:test";
+import assert from "node:assert/strict";
+import { isPrime } from "./isPrime.js";
 
+describe("isPrime function", () => {
+ test("should identify small prime numbers", () => {
+ const primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29];
+ for (const p of primes) {
+ assert.equal(isPrime(p), true, `${p} should be prime`);
+ }
+ });
+
+ test("should identify small non‑prime numbers", () => {
+ const nonPrimes = [0, 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 25, 100];
+ for (const n of nonPrimes) {
+ assert.equal(isPrime(n), false, `${n} should not be prime`);
+ }
+ });
+
+ test("should handle negative numbers and zero", () => {
+ const vals = [-10, -3, -1, 0];
+ for (const v of vals) {
+ assert.equal(isPrime(v), false, `${v} should not be prime`);
+ }
+ });
+
+ test("should reject non‑integer numbers", () => {
+ const vals = [2.5, 3.14, NaN, Infinity, -Infinity];
+ for (const v of vals) {
+ assert.equal(isPrime(v), false, `${v} should not be prime`);
+ }
+ });
+
+ test("should correctly evaluate a larger prime", () => {
+ assert.equal(isPrime(7919), true);
+ });
+
+ test("should correctly evaluate a larger composite", () => {
+ assert.equal(isPrime(8000), false);
+ });
+});
+